package module.main.view.mainInterface.friendListPanel
{
	import com.darwin.darwinUI.controls.IListItem;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.DarwinFont;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.events.MouseEvent;
	
	import main.App;
	
	import module.main.view.ResourceConst;
	
	/**
	 *	好友列表项 
	 * 	@author killsoon
	 */	
	public class FriendListItem extends UIComponent implements IListItem
	{
		private var userName:Label;
		private var _data:Object;
		private var userImage:Image;
		private var grade:Label;
		private var gradeStar:UIComponent;
		private var selectedBg:UIComponent;
		private var mouseSprite:UIComponent;
		
		public function FriendListItem()
		{
			super();
			initView();
			initListener();
		}
		
		private function initView():void
		{
			this.width = 125;
			this.height = 41;
			selectedBg = new UIComponent();
			selectedBg.backgroundSkin = ResourceConst.FRIENDLIST_SELECTED_BG;
			selectedBg.backgroundAuto = true;
			addChild(selectedBg);
			selectedBg.visible = false;
			
			mouseSprite = new UIComponent();
			mouseSprite.graphics.beginFill(0xffffff);
			mouseSprite.graphics.drawRect(0, 0, 125, 41);
			mouseSprite.graphics.endFill();
			mouseSprite.alpha = 0;
			addChild(mouseSprite);
			
			userImage = new Image();
			userImage.buttonMode = true;
			userImage.width = 35;
			userImage.height = 35;
			userImage.x = 4;
			userImage.y = 3;
			addChild(userImage);
			
			gradeStar = new UIComponent();
			gradeStar.backgroundSkin = ResourceConst.GRADE_ICON;
			gradeStar.backgroundAuto = true;
			gradeStar.x = 27;
			gradeStar.y = 9;
			addChild(gradeStar);
			
			grade = TextFieldFactory.getInstance().getLabel("friendlist_grade");
			gradeStar.addChild(grade);
			
			userName = TextFieldFactory.getInstance().getLabel("friendlist_name");
			userName.x = 60;
			userName.y = 6;
			addChild(userName);
		}
		
		private function initListener():void
		{
			addEventListener(MouseEvent.ROLL_OVER, rollOverItem);
			addEventListener(MouseEvent.ROLL_OUT, rollOutItem);
			addEventListener(MouseEvent.CLICK, friendClick);
		}
		
		private function rollOverItem(e:MouseEvent):void
		{
				selectedBg.visible = true;
		}
		
		private function rollOutItem(e:MouseEvent):void
		{
				selectedBg.visible = false;
		}
		
		private function friendClick(e:MouseEvent):void
		{
//			dispatchEvent(
		}
		
		public function set selected(v:Boolean):void
		{
			
		}
		
		public function get selected():Boolean
		{
			return false;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		public function set data(v:Object):void
		{
			_data = v;
			if(_data.hasOwnProperty("user_name")) 
			{
				userName.text = UIManager.getLanguageManager().getText("friendlist_name", [_data.user_name]);
			}
			if(_data.hasOwnProperty("grade"))
			{
				grade.text = UIManager.getLanguageManager().getText("friendlist_grade", [_data.grade]);
				grade.x = (gradeStar.width - grade.width) / 2;
				grade.y = (gradeStar.height - grade.height) / 2 + 5;
			}
			if(_data.hasOwnProperty("head_pic"))
			{
				userImage.source = _data.head_pic;
			}
		}
		
		public function get index():int
		{
			return 0;
		}
		
		public function set index(v:int):void
		{
		}
		
		public function dispose():void
		{
		}
	}
}